<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" /> -->
  <style>
    body,
    html {
      font-family: '宋体', Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, SimSun, sans-serif;
    }

    .notice {
      width: 300px;
      height: 100px;
      border-radius: 10px;
      outline: none;
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);
      overflow: hidden;
      display: flex;
      align-items: center;
      position: fixed;
      z-index: 2001;
      flex-direction: column;
    }

    .ui.buttons {
      display: flex;
      width: 100%;
      margin: 10px 0px;
      justify-content: space-around;
    }

    .button {
      width: 30%;
    }

    .button:nth-child(1) {
      outline: none;
      border: none;
      color: #fff;
      background-color: #000;
    }

    .button:nth-child(2) {
      outline: none;
      border: none;
      color: #fff;
      background-color: rgb(64, 64, 253);
    }

    .notice h3,
    p {
      padding: 0;
      margin: 1% 0;
    }

    .notice p {
      color: rgba(175, 171, 171, 0.809);
    }

    @keyframes backInRight {
      0% {
        -webkit-transform: translateX(2000px) scale(0.7);
        transform: translateX(2000px) scale(0.7);
        opacity: 0.7;
      }

      80% {
        -webkit-transform: translateX(0px) scale(0.7);
        transform: translateX(0px) scale(0.7);
        opacity: 0.7;
      }

      100% {
        -webkit-transform: scale(1);
        transform: scale(1);
        opacity: 1;
      }
    }

    .right {
      right: 0px;
      top: 10px;
      -webkit-animation-name: backInRight;
      animation-name: backInRight;
      animation-duration: 1s;
    }
  </style>
</head>

<body>
  <div id="app">
    <button @click="open">打开提示框</button>
  </div>
  <template id="Promptbox">
    <div class="notice right" v-if="this.show">
      <h3>
        <!-- <slot #title></slot> -->
        {{title}}
      </h3>
      <p>{{message}}</p>
      <div class="ui buttons">
        <button class="button" @click="determine">确定</button>
        <button class="button" @click="cancle">取消</button>
      </div>
    </div>
  </template>
  <script src='https://cdn.bootcss.com/vue/2.5.16/vue.min.js'></script>
  <script>
    let PromptboxOBJ = {
      template: "#Promptbox",
      data() {
        return {
          show: false,
          title: "",
          message: "",
          duration: 1000
        }
      },
      methods: {
        determine() {
          this.show = false
        },
        cancle() {
          this.show = true
        },
      },
      mounted() {
        setTimeout(() => {
          this.show = true
        }, this.duration);
      }
    }
    Vue.component('Promptbox', PromptboxOBJ)
    const Promptbox = Vue.extend(PromptboxOBJ)
    // 利用这个Promptbox构造函数可以new一个instance 这个上面会有$mount渲染方法,我们只需要appendChlid即可
    function notice(options) {
      const instance = new Promptbox({ data: options })
      instance.$mount()
      document.body.appendChild(instance.$el)
      return instance
    }
    const vm = new Vue({
      el: "#app",
      data: {
        str: "aaa"
      },
      methods: {
        open() {
          notice({ title: "提示", message: "nihaoya,this is a test notice", duration: 500 })
        },
      }
    })
  </script>
</body>

</html>